﻿using DevExpress.XtraCharts;
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXWinformReport
{
    public partial class FrmChart : DevExpress.XtraEditors.XtraForm
    {
        public FrmChart()
        {
            InitializeComponent();
        }

        private void FrmChart_Load(object sender, EventArgs e)
        {
            List<StudentNew> list = new List<StudentNew>()
            {
                new StudentNew(){StuId =1,StuName="Jseey",TotalScore =560.5M},
                new StudentNew(){StuId =2,StuName="Jerry",TotalScore =650.0M},
                new StudentNew(){StuId =3,StuName="Lucy",TotalScore =609.0M},
                new StudentNew(){StuId =4,StuName="Bruse",TotalScore =684.0M},
                new StudentNew(){StuId =5,StuName="White",TotalScore =598.6M},
                new StudentNew(){StuId =6,StuName="Felly",TotalScore =499.0M},
            };
            //条形图
            Series series01 = new Series("学生成绩", ViewType.Bar);
            //x轴的刻度数据类型
            series01.ArgumentScaleType = ScaleType.Qualitative;
            series01.ValueScaleType = ScaleType.Numerical;//  //y轴的刻度数据类型
            series01.ArgumentDataMember = "StuName";
            series01.ValueDataMembers[0] = "TotalScore";
            series01.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;//显示标签
            SideBySideBarSeriesLabel lblSetting = series01.Label as SideBySideBarSeriesLabel;
            lblSetting.Position = BarSeriesLabelPosition.Top;
            lblSetting.TextColor = Color.RosyBrown;
            series01.DataSource = list;//指定序列的数据源
            chartControl1.Series.Add(series01);

            //图例
            Legend lbar = new Legend("学生成绩统计");
            lbar.Title.Visible = true;
            lbar.Title.Text = "学生总分";
            lbar.Title.TextColor = Color.Red;
            chartControl1.Legends.Add(lbar);
            series01.Legend = lbar;//序列的图例


            //////线形图  表示不同学生的成绩，不太好
            //Series series02 = new Series("学生成绩2", ViewType.Line);
            ////x轴的刻度数据类型
            //series02.ArgumentScaleType = ScaleType.Qualitative;
            //series02.ValueScaleType = ScaleType.Numerical;//y轴的刻度的数据类型
            //series02.ArgumentDataMember = "StuName";
            //series02.ValueDataMembers[0] = "TotalScore";
            //series02.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;
            //series02.DataSource = list;//指定数据源
            //chartControl2.Series.Add(series02);

            //曲线图
            Series series03 = new Series("学生成绩3", ViewType.Spline);
            //x轴的刻度数据类型
            series03.ArgumentScaleType = ScaleType.Qualitative;
            series03.ValueScaleType = ScaleType.Numerical;//y轴的刻度的数据类型
            series03.ArgumentDataMember = "StuName";
            series03.ValueDataMembers[0] = "TotalScore";
            series03.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;
            series03.DataSource = list;//指定数据源
            chartControl2.Series.Add(series03);




            List<ClassScoreStatics> classList = new List<ClassScoreStatics>()
            {
                new ClassScoreStatics(){ClassId =1,ClassName="一班",HighCount=15,LowCount=5,MiddleCount=30},
                new ClassScoreStatics(){ClassId =2,ClassName="二班",HighCount=26,LowCount=8,MiddleCount=37},
                new ClassScoreStatics(){ClassId =3,ClassName="三班",HighCount=20,LowCount=1,MiddleCount=40},
                new ClassScoreStatics(){ClassId =4,ClassName="四班",HighCount=33,LowCount=10,MiddleCount=28},
                new ClassScoreStatics(){ClassId =5,ClassName="五班",HighCount=29,LowCount=4,MiddleCount=33},
                new ClassScoreStatics(){ClassId =6,ClassName="六班",HighCount=10,LowCount=6,MiddleCount=39},
                new ClassScoreStatics(){ClassId =7,ClassName="七班",HighCount=22,LowCount=13,MiddleCount=25}
            };

            Series series04 = new Series("高分学生人数统计", ViewType.Pie);
            series04.ArgumentScaleType = ScaleType.Qualitative;
            series04.ValueScaleType = ScaleType.Numerical;
            series04.ArgumentDataMember = "ClassName";
            series04.ValueDataMembers[0] = "HighCount";
            series04.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;
            series04.DataSource = classList;//指定数据源
            PieSeriesLabel lblPieSet = series04.Label as PieSeriesLabel;
            lblPieSet.Position = PieSeriesLabelPosition.Outside;
            series04.Label.TextPattern = "{A} { VP:0.00%}";//显示名称 百分比
            PieSeriesView view4 = new PieSeriesView();
            series04.View = view4;
            chartControl3.Series.Add(series04);

            //甜甜圈图
            Series series05 = new Series("不及格学生人数统计", ViewType.Doughnut);
            //x轴的刻度数据类型
            series05.ArgumentScaleType = ScaleType.Qualitative;
            series05.ValueScaleType = ScaleType.Numerical;//y轴的刻度的数据类型
            series05.ArgumentDataMember = "ClassName";
            series05.ValueDataMembers[0] = "LowCount";
            series05.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;
            series05.DataSource = classList;//指定数据源
            DoughnutSeriesLabel lblSet2 = series05.Label as DoughnutSeriesLabel;
            lblSet2.Position = PieSeriesLabelPosition.Outside;
            series05.Label.TextPattern = "{A} { VP:0.00%}";//显示名称 百分比
            DoughnutSeriesView view5 = new DoughnutSeriesView();
            series05.View = view5;
            chartControl3.Series.Add(series05);

            Series series06 = new Series("中等分数人数统计", ViewType.Doughnut3D);//3D甜甜圈图
            //x轴的刻度数据类型
            series06.ArgumentScaleType = ScaleType.Qualitative;
            series06.ValueScaleType = ScaleType.Numerical;//y轴的刻度的数据类型
            series06.ArgumentDataMember = "ClassName";
            series06.ValueDataMembers[0] = "MiddleCount";
            series06.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;
            series06.DataSource = classList;//指定数据源
            Doughnut3DSeriesLabel lblSet3 = series06.Label as Doughnut3DSeriesLabel;
            lblSet3.Position = PieSeriesLabelPosition.Outside;
            series06.Label.TextPattern = "{A} { VP:0.00%}";//显示名称 百分比
            //series06.CrosshairContentShowMode = CrosshairContentShowMode.Label;
            Doughnut3DSeriesView view6 = new Doughnut3DSeriesView();
            series06.View = view6;
            chartControl4.Series.Add(series06);
        }
    }
}